package com.baidu.filter;

import com.baidu.pojo.Power;
import com.baidu.service.PowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.servlet.*;
import java.io.IOException;
import java.util.List;

@Configuration("roleFilter")
public class RoleFilter implements Filter {
    @Autowired
    private PowerService powerService;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
    //    查询所有角色，并在login.jsp显示
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        List<Power> list=powerService.getAllRole();

        //将集合保存到HttpServletRequest中
        servletRequest.setAttribute("list",list);

        //请求向下传递
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
